package connection;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientConnection {

public 	Socket clientSocket;
	DataOutputStream outToServer;
	BufferedReader inFromServer;

	String sentence;
	String modifiedSentence;
	BufferedReader inFromUser;
String user="client2";
	public ClientConnection() {
		inFromUser = new BufferedReader(new InputStreamReader(System.in));
		try {
			clientSocket = new Socket("192.168.1.102", 6789);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			outToServer = new DataOutputStream(clientSocket.getOutputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			inFromServer = new BufferedReader(new InputStreamReader(
					clientSocket.getInputStream()));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			sendMessage(user);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void sendMessage(String message) throws IOException {
		outToServer.writeBytes(message + '\n');
	}

	public String getMessage() throws IOException {
		return modifiedSentence = inFromServer.readLine();
	}

}